<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="人脸标识" prop="faceId">
        <el-input
          v-model="queryParams.faceId"
          placeholder="请输入人脸标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备编码" prop="deviceId">
        <el-input
          v-model="queryParams.deviceId"
          placeholder="请输入设备编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['viid:face:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['viid:face:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['viid:face:remove']"
        >删除
        </el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['viid:face:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="faceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="人脸标识" align="center" prop="faceId"/>
<!--      <el-table-column label="信息分类" align="center" prop="infoKind"/>
      <el-table-column label="来源标识" align="center" prop="sourceId"/>-->
      <el-table-column label="设备编码" align="center" prop="deviceId"/>
      <el-table-column label="拍摄时间" align="center" prop="shotTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.shotTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="左上角X坐标" align="center" prop="leftTopX"/>
      <el-table-column label="左上角Y坐标" align="center" prop="leftTopY"/>
      <el-table-column label="右下角X坐标" align="center" prop="rightBtmX"/>
      <el-table-column label="右下角Y坐标" align="center" prop="rightBtmY"/>-->
      <el-table-column label="位置标记时间" align="center" prop="locationMarkTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.locationMarkTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="人脸出现时间" align="center" prop="faceAppearTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.faceAppearTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="人脸消失时间" align="center" prop="faceDisAppearTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.faceDisAppearTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="性别代码" align="center" prop="genderCode"/>
      <el-table-column label="年龄上限" align="center" prop="ageUpLimit"/>
      <el-table-column label="年龄下限" align="center" prop="ageLowerLimit"/>
      <el-table-column label="眼镜款式" align="center" prop="glassStyle"/>
      <el-table-column label="是否驾驶员" align="center" prop="isDriver">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isDriver === '0'">否</el-tag>
          <el-tag v-if="scope.row.isDriver === '1'" type="success">是</el-tag>
          <el-tag v-if="scope.row.isDriver === '2'" type="warning">不确定</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否涉外人员" align="center" prop="isForeigner">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isForeigner === '0'">否</el-tag>
          <el-tag v-if="scope.row.isForeigner === '1'" type="success">是</el-tag>
          <el-tag v-if="scope.row.isForeigner === '2'" type="warning">不确定</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否涉恐人员" align="center" prop="isSuspectedTerrorist">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isSuspectedTerrorist === '0'">否</el-tag>
          <el-tag v-if="scope.row.isSuspectedTerrorist === '1'" type="success">是</el-tag>
          <el-tag v-if="scope.row.isSuspectedTerrorist === '2'" type="warning">不确定</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否涉案人员" align="center" prop="isCriminalInvolved">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isCriminalInvolved === '0'">否</el-tag>
          <el-tag v-if="scope.row.isCriminalInvolved === '1'" type="success">是</el-tag>
          <el-tag v-if="scope.row.isCriminalInvolved === '2'" type="warning">不确定</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否在押人员" align="center" prop="isDetainess">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isDetainess === '0'">否</el-tag>
          <el-tag v-if="scope.row.isDetainess === '1'" type="success">是</el-tag>
          <el-tag v-if="scope.row.isDetainess === '2'" type="warning">不确定</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否被害人" align="center" prop="isVictim">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isVictim === '0'">否</el-tag>
          <el-tag v-if="scope.row.isVictim === '1'" type="success">是</el-tag>
          <el-tag v-if="scope.row.isVictim === '2'" type="warning">不确定</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否可疑人员" align="center" prop="isSuspiciousPerson">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isSuspiciousPerson === '0'">否</el-tag>
          <el-tag v-if="scope.row.isSuspiciousPerson === '1'" type="success">是</el-tag>
          <el-tag v-if="scope.row.isSuspiciousPerson === '2'" type="warning">不确定</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="相似度[0,1]" align="center" prop="similaritydegree"/>
      <el-table-column label="上传时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['viid:face:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['viid:face:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改人脸信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="人脸标识" prop="faceId">
          <el-input v-model="form.faceId" placeholder="请输入人脸标识"/>
        </el-form-item>
        <el-form-item label="信息分类：人工采集、自动采集" prop="infoKind">
          <el-input v-model="form.infoKind" placeholder="请输入信息分类：人工采集、自动采集"/>
        </el-form-item>
        <el-form-item label="来源标识：来源图像信息标识" prop="sourceId">
          <el-input v-model="form.sourceId" placeholder="请输入来源标识：来源图像信息标识"/>
        </el-form-item>
        <el-form-item label="设备编码" prop="deviceId">
          <el-input v-model="form.deviceId" placeholder="请输入设备编码"/>
        </el-form-item>
        <el-form-item label="拍摄时间" prop="shotTime">
          <el-date-picker clearable
                          v-model="form.shotTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择拍摄时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="左上角X坐标" prop="leftTopX">
          <el-input v-model="form.leftTopX" placeholder="请输入左上角X坐标"/>
        </el-form-item>
        <el-form-item label="左上角Y坐标" prop="leftTopY">
          <el-input v-model="form.leftTopY" placeholder="请输入左上角Y坐标"/>
        </el-form-item>
        <el-form-item label="右下角X坐标" prop="rightBtmX">
          <el-input v-model="form.rightBtmX" placeholder="请输入右下角X坐标"/>
        </el-form-item>
        <el-form-item label="右下角Y坐标" prop="rightBtmY">
          <el-input v-model="form.rightBtmY" placeholder="请输入右下角Y坐标"/>
        </el-form-item>
        <el-form-item label="位置标记时间" prop="locationMarkTime">
          <el-date-picker clearable
                          v-model="form.locationMarkTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择位置标记时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="人脸出现时间" prop="faceAppearTime">
          <el-date-picker clearable
                          v-model="form.faceAppearTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择人脸出现时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="人脸消失时间" prop="faceDisAppearTime">
          <el-date-picker clearable
                          v-model="form.faceDisAppearTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择人脸消失时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="性别代码" prop="genderCode">
          <el-input v-model="form.genderCode" placeholder="请输入性别代码"/>
        </el-form-item>
        <el-form-item label="年龄上限" prop="ageUpLimit">
          <el-input v-model="form.ageUpLimit" placeholder="请输入年龄上限"/>
        </el-form-item>
        <el-form-item label="年龄下限" prop="ageLowerLimit">
          <el-input v-model="form.ageLowerLimit" placeholder="请输入年龄下限"/>
        </el-form-item>
        <el-form-item label="眼镜款式" prop="glassStyle">
          <el-input v-model="form.glassStyle" placeholder="请输入眼镜款式"/>
        </el-form-item>
        <el-form-item label="不清楚字段含义" prop="emotion">
          <el-input v-model="form.emotion" placeholder="请输入不清楚字段含义"/>
        </el-form-item>
        <el-form-item label="是否驾驶员 0：否、1：是、2：不确定" prop="isDriver">
          <el-input v-model="form.isDriver" placeholder="请输入是否驾驶员 0：否、1：是、2：不确定"/>
        </el-form-item>
        <el-form-item label="是否涉外人员 0：否、1：是、2：不确定" prop="isForeigner">
          <el-input v-model="form.isForeigner" placeholder="请输入是否涉外人员 0：否、1：是、2：不确定"/>
        </el-form-item>
        <el-form-item label="是否涉恐人员 0：否、1：是、2：不确定" prop="isSuspectedTerrorist">
          <el-input v-model="form.isSuspectedTerrorist" placeholder="请输入是否涉恐人员 0：否、1：是、2：不确定"/>
        </el-form-item>
        <el-form-item label="是否涉案人员 0：否、1：是、2：不确定" prop="isCriminalInvolved">
          <el-input v-model="form.isCriminalInvolved" placeholder="请输入是否涉案人员 0：否、1：是、2：不确定"/>
        </el-form-item>
        <el-form-item label="是否在押人员 0：否、1：是、2：不确定" prop="isDetainess">
          <el-input v-model="form.isDetainess" placeholder="请输入是否在押人员 0：否、1：是、2：不确定"/>
        </el-form-item>
        <el-form-item label="是否被害人 0：否、1：是、2：不确定" prop="isVictim">
          <el-input v-model="form.isVictim" placeholder="请输入是否被害人 0：否、1：是、2：不确定"/>
        </el-form-item>
        <el-form-item label="是否可疑人员 0：否、1：是、2：不确定" prop="isSuspiciousPerson">
          <el-input v-model="form.isSuspiciousPerson" placeholder="请输入是否可疑人员 0：否、1：是、2：不确定"/>
        </el-form-item>
        <el-form-item label="相似度[0,1]" prop="similaritydegree">
          <el-input v-model="form.similaritydegree" placeholder="请输入相似度[0,1]"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listFace, getFace, delFace, addFace, updateFace} from "@/api/viid/face";

export default {
  name: "Face",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人脸信息表格数据
      faceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        faceId: null,
        infoKind: null,
        sourceId: null,
        deviceId: null,
        shotTime: null,
        leftTopX: null,
        leftTopY: null,
        rightBtmX: null,
        rightBtmY: null,
        locationMarkTime: null,
        faceAppearTime: null,
        faceDisAppearTime: null,
        genderCode: null,
        ageUpLimit: null,
        ageLowerLimit: null,
        glassStyle: null,
        emotion: null,
        isDriver: null,
        isForeigner: null,
        isSuspectedTerrorist: null,
        isCriminalInvolved: null,
        isDetainess: null,
        isVictim: null,
        isSuspiciousPerson: null,
        similaritydegree: null,
        orderByColumn: "create_time",
        isAsc: "desc"
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询人脸信息列表 */
    getList() {
      this.loading = true;
      listFace(this.queryParams).then(response => {
        this.faceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        faceId: null,
        infoKind: null,
        sourceId: null,
        deviceId: null,
        shotTime: null,
        leftTopX: null,
        leftTopY: null,
        rightBtmX: null,
        rightBtmY: null,
        locationMarkTime: null,
        faceAppearTime: null,
        faceDisAppearTime: null,
        genderCode: null,
        ageUpLimit: null,
        ageLowerLimit: null,
        glassStyle: null,
        emotion: null,
        isDriver: null,
        isForeigner: null,
        isSuspectedTerrorist: null,
        isCriminalInvolved: null,
        isDetainess: null,
        isVictim: null,
        isSuspiciousPerson: null,
        similaritydegree: null,
        createTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加人脸信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFace(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改人脸信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFace(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFace(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除人脸信息编号为"' + ids + '"的数据项？').then(function () {
        return delFace(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('viid/face/export', {
        ...this.queryParams
      }, `face_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
